<style lang="scss" scoped>
.online {
  background-color: #f5f5f5;
  height: 100%;
  user-select: none;
}
.onlineWrapper {
  width: 80%;
  margin: 0 auto;
  header {
    height: 50px;
    font-size: 16px;
    line-height: 50px;
    color: #606060;
    span {
      font-size: 18px;
      font-weight: 500;
      color: black;
    }
  }
  .onlineConcent {
    box-sizing: border-box;
    border: 1px solid #dddddd;
    box-shadow: 2px 2px 5px rgb(0, 0, 0, 0.3);
    background-color: white;
    .onlineConcentHeader {
      height: 50px;
      border-bottom: 1px solid #dddddd;
      font-size: 18px;
      font-weight: 400;
      display: flex;
      align-items: center;
      padding: 0 20px;
      .itemList {
        font-size: 25px;
        color: #fdd869;
        margin-right: 10px;
      }
    }
    .onlineConcentMain {
      width: 100%;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      .mainItem {
        padding: 20px 30px;
        width: 50%;
        box-sizing: border-box;
      }

      .onlineList {
        display: flex;
        .onlineListTitle {
          display: block;
          height: 65px;
          width: 65px;
          border-radius: 50%;
          color: white;
          background-color: #fbd869;
          display: flex;
          font-size: 15px;
          display: flex;
          align-items: center;
          justify-content: center;
          span {
            padding: 10px;
          }
        }
        .onlineListConcent {
          width: 80%;
          height: 170px;
          background-color: #f4f4f4;
          border-radius: 10px;
          margin-left: 25px;
          position: relative;
          padding: 15px 45px;
          box-sizing: border-box;
          &::after {
            content: "";
            display: block;
            border-top: 15px solid transparent;
            border-right: 15px solid #f4f4f4;
            border-bottom: 15px solid transparent;
            position: absolute;
            left: -14px;
            top: 18px;
          }
          ul {
            list-style-type: none;
            padding: 0;
            margin: 0;
            li {
              display: flex;
              p {
                margin: 0;
                width: 40%;
                font-size: 18px;
                line-height: 46px;
                color: black;
              }
              .controls {
                width: 60%;
                display: flex;
                align-items: center;
                justify-content: space-between;
                span {
                  line-height: 46px;
                  font-size: 16px;
                  color: #616161;
                  margin-right: 40px;
                }
                .el-switch {
                  --el-switch-off-color: #dddddd;
                  --el-switch-on-color: #fdb869;
                  margin-left: 20px;
                }
              }
            }
          }
        }
      }
    }
  }
  .pag {
    width: 100%;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
</style>

<template>
  <div class="online">
    <div class="onlineWrapper">
      <header><span>场馆维护 / 场馆设置 /</span> 项目上下线</header>
      <div class="onlineConcent">
        <div class="onlineConcentHeader">
          <el-icon class="itemList"><Tickets /></el-icon>
          项目列表
        </div>
        <div class="onlineConcentMain">
          <div class="mainItem" v-for="item in stadiumList" :key="item.id">
            <div class="onlineList">
              <div class="onlineListTitle">
                <span> {{ item.name }}</span>
              </div>
              <div class="onlineListConcent">
                <ul>
                  <li>
                    <p>
                      {{
                        item.sports.length > 0
                          ? item.sports[0].sport_type_codeName
                          : "暂无数据"
                      }}
                    </p>
                    <div class="controls">
                      <span>{{ status }}</span>
                      <el-switch v-model="switchOn"/>
                    </div>
                  </li>
                </ul>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- 分页 -->
      <div class="pag">
        <el-pagination
          background
          layout="prev, pager, next"
          @current-change="currentChange"
          :total="stadiumPagination.total"
          v-model:page-size="stadiumPagination.size"
        />
      </div>
    </div>
  </div>
</template>

<script setup>
// 引入获取场馆设置接口
import { GetStadium } from "@/api/stadium";
import { ref,watch } from "vue";
// const value1 = ref(true)

// 定义开关状态变量
const switchOn = ref(true);

// 监听开关状态变量
watch(switchOn, (newVal) => {
  status.value = newVal ? '已上线' : '已下线';
});

// 定义状态文本变量
const status = ref('已上线');
// 场地列表数据
const stadiumList = ref("");
//发送场馆请求所需要的数据
const stadiumPagination = ref({ size: 1 });
// 获取场地数据
const getStadium = () => {
  GetStadium(stadiumPagination.value).then((res) => {
    stadiumList.value = res.data.data;
    stadiumPagination.value = res.data.pagination;
  });
};
getStadium();
// 分页点击事件
const currentChange = (val) => {
  stadiumPagination.value.current = val;
  getStadium();
};
</script>
